package container;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

/**
 * Class which is used as a container for {@link WeaponTraitDescription}s and
 * makes it easier to store many {@link WeaponTraitDescription} through a JAXB
 * marshaller.
 * 
 * @author Marcus
 * 
 */
@XmlRootElement
public class WeaponTraitDescriptions {
	private List<WeaponTraitDescription> traitDescriptions = new ArrayList<WeaponTraitDescription>();

	/**
	 * Addds the passed trait to the list.
	 * 
	 * @param trait
	 *            trait to add
	 */
	public void addTraitDescription(WeaponTraitDescription trait) {
		if(this.traitDescriptions.contains(trait)){
			this.removeTraitDescription(trait);
		}
		this.traitDescriptions.add(trait);
		
		Collections.sort(this.traitDescriptions);
	}

	/**
	 * Removes the passed trait to the list.
	 * 
	 * @param trait
	 *            trait to add
	 */
	public void removeTraitDescription(WeaponTraitDescription trait) {
		this.traitDescriptions.remove(trait);
	}

	/**
	 * @return the traitDesiptions
	 */
	@XmlElement(name = "Weapon_Trait")
	public List<WeaponTraitDescription> getTraitDescriptions() {
		return this.traitDescriptions;
	}

	/**
	 * @param traitDesiptions
	 *            the traitDesiptions to set
	 */
	public void setTraitDescriptions(
			List<WeaponTraitDescription> traitDesiptions) {
		this.traitDescriptions = traitDesiptions;
	}

}
